/* eslint-disable */
import Vue from 'vue';
import { MessageBox } from 'element-ui';
import Config from './config.js';
// import {
//     CONTROL_IMPORT,
//     CONTROL_DOWNTEMP,
//     COMMON_UPLOAD
// } from '/@/api/global.js'

let Hub = new Vue();
export default {
  getKeyAndValue(value, name) {
    let data = [
      { value: 'brandName', name: '品牌名称', type: 'string' },
      { value: 'company', name: '供应商', type: 'string' },
      { value: 'createTime', name: '创建时间', type: 'string' },
      { value: 'ecology', name: '业态', type: 'string' },
      { value: 'goodsCode', name: '物资编码', type: 'string' },
      { value: 'goodsName', name: '物资编码', type: 'string' },
      { value: 'goodsNumber', name: '物资数量', type: 'integer' },
      { value: 'goodsPrice', name: '物资价格', type: 'number' },
      { value: 'goodsTemplateCode', name: '所属物资档案编码', type: 'string' },
      { value: 'goodsTemplateName', name: '所属物资档案名称', type: 'string' },
      { value: 'id', name: 'id', type: 'string' },
      { value: 'imgList', name: '物资图片', type: 'array' },
      { value: 'itemDTOList', name: '物资属性', type: 'array' },
      { value: 'producer', name: '生产地', type: 'string' },
      { value: 'videoList', name: '物资视频', type: 'array' },
    ];
    for (let e in data) {
      if (data[e].value == value) {
        return data[e][name];
      }
    }
    return '未知';
  },
  // Event Bus
  Hub() {
    return Hub;
  },
  // api接口前缀
  getApiUrl() {
    return process.env.VUE_APP_APIURL;
  },
  // session
  getSession() {
    let userInfo = JSON.parse(localStorage.getItem('userInfo'));
    if (userInfo && userInfo.session_id) {
      return userInfo.session_id;
    }
  },
  // 文件上传api
  uploadURL() {
    return process.env.VUE_APP_UPLOAD_URL;
  },

  /**
   * 文件上传失败回调
   */
  uploadError(err, file, fileList) {
    if (err) {
      if (err.status === 403) {
        // 非法的 sessionId，跳转到登录页
        store.dispatch(storeTypes.USER_SIGN_OUT, 'invalid_session');
        ElementUI.Message({
          type: 'error',
          message: '您的登录帐号已发生变化，请重新登录！',
        });
      } else {
        ElementUI.Message({
          type: 'error',
          message: err.msg ? err.msg : '操作失败，请重试！',
        });
      }
    }
  },
  // 对象的克隆
  cloneObj(obj) {
    var o;
    if (typeof obj === 'object' && obj !== null) {
      if (Array.isArray(obj)) {
        o = [];
        for (var i = 0, len = obj.length; i < len; i++) {
          o.push(this.cloneObj(obj[i]));
        }
      } else {
        o = {};
        for (var k in obj) {
          o[k] = this.cloneObj(obj[k]);
        }
      }
    }
    return o;
  },
  parseTime(time, cFormat) {
    if (arguments.length === 0 || !time) {
      return null
    }
    const format = cFormat || '{y}-{m}-{d}'
    let date
    if (typeof time === 'object') {
      date = time
    } else {
      date = new Date(time)
    }
    const formatObj = {
      y: date.getFullYear(),
      m: date.getMonth() + 1,
      d: date.getDate(),
      h: date.getHours(),
      i: date.getMinutes(),
      s: date.getSeconds(),
      a: date.getDay()
    }
    const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => {
      const value = formatObj[key]
      // Note: getDay() returns 0 on Sunday
      if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value] }
      return value.toString().padStart(2, '0')
    })
    return time_str
  },
  // 转换时间日期格式
  addTime(m) {
    return m < 10 ? '0' + m : m;
  },
  format(timeTemp) {
    let _self = this;
    let time = new Date(timeTemp);
    let y = time.getFullYear();
    let m = time.getMonth() + 1;
    let d = time.getDate();
    let h = time.getHours();
    let mm = time.getMinutes();
    let s = time.getSeconds();
    let date =
      y +
      '-' +
      _self.addTime(m) +
      '-' +
      _self.addTime(d) +
      ' ' +
      _self.addTime(h) +
      ':' +
      _self.addTime(mm) +
      ':' +
      _self.addTime(s);
    return date;
  },

  //  计算天数
  addDate(dateStr, diffDay) {
    var dateTime = new Date(dateStr).getTime();
    var diffTimeLong = dateTime + diffDay * 24 * 3600 * 1000;
    var diffTime = new Date(diffTimeLong);
    var m = diffTime.getMonth() + 1 < 10 ? '0' + (diffTime.getMonth() + 1) : diffTime.getMonth() + 1;
    var d = diffTime.getDate() < 10 ? '0' + diffTime.getDate() : diffTime.getDate();
    return diffTime.getFullYear() + '-' + m + '-' + d;
  },

  convertCurrency(money) {
    //汉字的数字
    var cnNums = new Array('零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖');
    //基本单位
    var cnIntRadice = new Array('', '拾', '佰', '仟');
    //对应整数部分扩展单位
    var cnIntUnits = new Array('', '万', '亿', '兆');
    //对应小数部分单位
    var cnDecUnits = new Array('角', '分', '毫', '厘');
    //整数金额时后面跟的字符
    var cnInteger = '整';
    //整型完以后的单位
    var cnIntLast = '元';
    //最大处理的数字
    var maxNum = 999999999999999.9999;
    //金额整数部分
    var integerNum;
    //金额小数部分
    var decimalNum;
    //输出的中文金额字符串
    var chineseStr = '';
    //分离金额后用的数组，预定义
    var parts;
    if (money == '') {
      return '';
    }
    money = parseFloat(money);
    if (money >= maxNum) {
      //超出最大处理数字
      return '';
    }
    if (money == 0) {
      chineseStr = cnNums[0] + cnIntLast + cnInteger;
      return chineseStr;
    }
    //转换为字符串
    money = money.toString();
    if (money.indexOf('.') == -1) {
      integerNum = money;
      decimalNum = '';
    } else {
      parts = money.split('.');
      integerNum = parts[0];
      decimalNum = parts[1].substr(0, 4);
    }
    //获取整型部分转换
    if (parseInt(integerNum, 10) > 0) {
      var zeroCount = 0;
      var IntLen = integerNum.length;
      for (var i = 0; i < IntLen; i++) {
        var n = integerNum.substr(i, 1);
        var p = IntLen - i - 1;
        var q = p / 4;
        var m = p % 4;
        if (n == '0') {
          zeroCount++;
        } else {
          if (zeroCount > 0) {
            chineseStr += cnNums[0];
          }
          //归零
          zeroCount = 0;
          chineseStr += cnNums[parseInt(n)] + cnIntRadice[m];
        }
        if (m == 0 && zeroCount < 4) {
          chineseStr += cnIntUnits[q];
        }
      }
      chineseStr += cnIntLast;
    }
    //小数部分
    if (decimalNum != '') {
      var decLen = decimalNum.length;
      for (var i = 0; i < decLen; i++) {
        var n = decimalNum.substr(i, 1);
        if (n != '0') {
          chineseStr += cnNums[Number(n)] + cnDecUnits[i];
        }
      }
    }
    if (chineseStr == '') {
      chineseStr += cnNums[0] + cnIntLast + cnInteger;
    } else if (decimalNum == '') {
      chineseStr += cnInteger;
    }
    return chineseStr;
  },

  //中国标准时间月转换
  dateZN(e) {
    let d = new Date(e);
    return `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}`;
  },

  // 转换日期时间格式（数组）
  formatDate(timeTemp) {
    if (Array.isArray(timeTemp)) {
      if (!timeTemp.length) return ['', ''];
      return timeTemp.map((date) => this.format(date));
    } else {
      return timeTemp ? this.format(timeTemp) : '';
    }
  },
  /**
   * 获取字符串长度
   */
  lenStr(str) {
    str = str + 'a';
    var str1 = str.match(/[\x00-\xff]/g).length;
    return (str.length - str1) * 2 + str1 - 1;
  },
  /**
   * 匹配正则
   */
  matchFn(type, value) {
    let match = {
      // 链接
      url: /^((ht|f)tps?):\/\/[\w\-]+(\.[\w\-]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?$/gi,
      // 固话
      phone:
        /^((\d{8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$/gi,
      // 手机号码
      tel: /^1[34578]\d{9}$/gi,
      // 6位数密码验证
      passWord: /^\d{6,}$/gi,
      // 正整数（不包含0）
      positiveInt: /^[1-9]\d*$/gi,
      // 非负整数（包含0）
      nonnegativeInt: /^[1-9]\d*|0$/gi,
      // 浮点
      float: /^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$/gi,
      // 小数点后不超过两位
      floatFixedTwo: /^\d+(\.\d{1,2})?$/gi,
      // 邮编
      postcode: /^[1-9]\d{5}(?!\d)$/gi,
      // 邮箱
      email: /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/gi,
      // 字母或数字
      letterOrNum: /^[a-zA-Z\d]+$/gi,
      // 10位，第一个不能为0
      // 可以输入中文，字母，数字
      room: /^[\u4e00-\u9fa5_a-zA-Z1-9_][\u4e00-\u9fa5_a-zA-Z0-9_]{0,10}$/gi,
      // 身份证
      identity_no: /^\d{15}|\d{18}$/gi,
    };
    return match[type].test(value);
  },
  /**
   * 获取链接后面的参数
   * @param String name 需要获取的参数名字
   */
  getQueryString(name) {
    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
    var r = window.location.search.substr(1).match(reg);
    return r != null ? unescape(r[2]) : null;
  },
  /**
   * 获取文件后缀
   * @param {*} name
   */
  getExtension(name) {
    let ext = null;
    let filename = name.toLowerCase();
    let i = filename.lastIndexOf('.');
    if (i > -1) {
      ext = filename.substring(i);
    }
    return ext;
  },
  /**
   * str 数据
   */
  toBoole(str) {
    let boole = null;
    if (typeof str === 'string') {
      // 字符串类型
      if (str === 'false') {
        boole = false;
      } else if (str === 'true') {
        boole = true;
      }
    } else if (typeof str === 'boolean') {
      // 布尔类型
      boole = str;
    }
    return boole;
  },
  /**
   * 保存权限
   */
  savePermissions(power_list) {
    let permissions = {};
    this.flatten(power_list, 'sub_power').forEach((item) => {
      let { powerId, powerName, showMenu } = item;
      permissions[powerId] = {
        powerName,
        showMenu,
      };
    });
    localStorage.setItem('permissions', JSON.stringify(permissions));
  },
  /**
   * 平铺数组
   */
  flatten(arr, children) {
    if (!arr) return [];
    return arr.reduce((prev, item) => prev.concat(item, this.flatten(item[children], children)), []);
  },
  /**
   * 导出Excel
   */
  exportExcelFun(d, urlParams) {
    let session = JSON.parse(localStorage.getItem('userInfo')).sessionId;
    let apiUrl = this.getApiUrl();
    let appkey = '67167560c2424f2c92kxkw3c0af958hj';
    let data = {
      ...d,
      appkey,
      session,
    };
    urlParams = urlParams + '?';
    for (let key in data) {
      urlParams += `${key}=${data[key]}&`;
    }
    apiUrl += urlParams.slice(0, -1);
    window.open(apiUrl);
  },
  // 二次确认框
  confirmCallback(title, callback) {
    MessageBox.confirm(title, '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
    })
      .then(() => {
        return callback();
      })
      .catch(() => { });
  },
  isBlank(value) {
    return value === null || value === undefined || value === 'null' || value === 'undefined' || value === '';
  },

  //下载模版
  async download(fileName, url) {
    let response = await fetch(url); // 内容转变成blob地址
    let blob = await response.blob(); // 创建隐藏的可下载链接
    let objectUrl = window.URL.createObjectURL(blob);
    let a = document.createElement('a');
    a.href = objectUrl;
    a.download = fileName;
    a.click();
    a.remove();
  },
  // downloadFile(url){

  //     const blob = new Blob([data], {
  //         type:
  //             "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
  //     });
  // const downloadElement = document.createElement("a");
  // const href = window.URL.createObjectURL(blob); //创建下载的链接
  // downloadElement.href = href;
  // downloadElement.download = name; //下载后文件名
  // document.body.appendChild(downloadElement);
  // downloadElement.click(); //点击下载
  // document.body.removeChild(downloadElement); //下载完成移除元素
  // window.URL.revokeObjectURL(href);

  //     // let response =  fetch(url); // 内容转变成blob地址
  //     // let blob =  response.blob(); // 创建隐藏的可下载链接
  //     // let objectUrl = window.URL.createObjectURL(blob);
  //     // let a = document.createElement('a');
  //     // a.href = objectUrl;

  //     // a.click()
  //     // a.remove();
  // },
  //获取上传接口
  // getuploaldurl(e) {
  //     const type = {
  //         "control": CONTROL_IMPORT,
  //         "public": COMMON_UPLOAD
  //     }
  //     const src = type[e]
  //     return this.getApiUrl() + src
  // },
  /**
   * 文件上传前执行函数
   */
  beforeUpload() {
    // if (uploadEl) {
    //     if (Array.isArray(uploadEl)) {
    //         window.combineHeader(uploadEl[0].headers)
    //     } else {
    return window.combineHeader(Config.header);
    // }
    // }
  },
  // 权限判断
  getRoleIds(rank, path) {
    const data = [
      // {
      //   name: "数据看榜",
      //   subTabTitle: "数据看榜",
      //   icon: require("../assets/images/sjkb.png"),
      //   icon2: require("../assets/images/sjkb-n.png"),
      //   path: "/dataBoard",
      //   auth: true,
      // },
      // {
      //   name: "数据统计",
      //   subTabTitle: "数据统计",
      //   icon: require("../assets/images/jbtz.png"),
      //   icon2: require("../assets/images/jbtz-n.png"),
      //   path: "/standingBook",
      //   auth: true,
      // },
      // {
      //   name: "办理中心",
      //   subTabTitle: "办理中心",
      //   icon: require("../assets/images/jblb.png"),
      //   icon2: require("../assets/images/jblb-n.png"),
      //   path: "/reportList",
      //   auth: true,
      // },
      // {
      //   name: "组织管理",
      //   subTabTitle: "组织管理",
      //   icon: require("../assets/images/zzgl.png"),
      //   icon2: require("../assets/images/zzgl-n.png"),
      //   path: "/dataPermission",
      //   auth: true,
      // },
      // {
      //   name: "人员管理",
      //   subTabTitle: "人员管理",
      //   icon: require("../assets/images/rygl.png"),
      //   icon2: require("../assets/images/rygl-n.png"),
      //   path: "/peopleManage",
      //   auth: true,
      // },
      // {
      //     name: "字典管理",
      //     subTabTitle: "字典管理",
      //     icon: require("../assets/images/zdgl.png"),
      //     icon2: require("../assets/images/zdgl-n.png"),
      //     path: "/dictionaryManaged",
      //     auth: true,
      // },
    ];

    let returnData = [];

    if (rank == 1) {
      returnData.tabsList = data;
      if (path) {
        returnData.YN = true;
      }
      returnData.roleIds = ['/dataBoard', '/reportList', '/standingBook', '/dataPermission', '/peopleManage'];
    } else if (rank == 2) {
      let ranks2 = ['/dataBoard', '/reportList', '/standingBook'];
      if (path) {
        returnData.YN = ranks2.indexOf(path) != -1;
      }
      let item = [];
      for (let e in data) {
        if (ranks2.indexOf(data[e].path) != -1) {
          item.push(data[e]);
        }
      }
      returnData.tabsList = item;
      returnData.roleIds = ranks2;
    } else if (rank == 3) {
      let ranks3 = ['/dataBoard', '/reportList', '/standingBook'];
      if (path) {
        returnData.YN = ranks3.indexOf(path) != -1;
      }
      let item = [];
      for (let e in data) {
        if (ranks3.indexOf(data[e].path) != -1) {
          item.push(data[e]);
        }
      }
      returnData.tabsList = item;
      returnData.roleIds = ranks3;
    } else if (rank == 4) {
      let ranks4 = ['/dataBoard', '/standingBook'];
      if (path) {
        returnData.YN = ranks4.indexOf(path) != -1;
      }
      let item = [];
      for (let e in data) {
        if (ranks4.indexOf(data[e].path) != -1) {
          item.push(data[e]);
        }
      }
      returnData.tabsList = item;
      returnData.roleIds = ranks4;
    }

    return returnData;
    // const
  },
  //获取文件mine
  getMime(name) {
    const data = [
      {
        type: 'application/envoy',
        value: 'evy',
      },
      {
        type: 'application/fractals',
        value: 'fif',
      },
      {
        type: 'application/futuresplash',
        value: 'spl',
      },
      {
        type: 'application/hta',
        value: 'hta',
      },
      {
        type: 'application/internet-property-stream',
        value: 'acx',
      },
      {
        type: 'application/mac-binhex40',
        value: 'hqx',
      },
      {
        type: 'application/msword',
        value: 'doc',
      },
      {
        type: 'application/msword',
        value: 'dot',
      },
      {
        type: 'application/octet-stream',
        value: '*',
      },
      {
        type: 'application/octet-stream',
        value: 'bin',
      },
      {
        type: 'application/octet-stream',
        value: 'class',
      },
      {
        type: 'application/octet-stream',
        value: 'dms',
      },
      {
        type: 'application/octet-stream',
        value: 'exe',
      },
      {
        type: 'application/octet-stream',
        value: 'lha',
      },
      {
        type: 'application/octet-stream',
        value: 'lzh',
      },
      {
        type: 'application/oda',
        value: 'oda',
      },
      {
        type: 'application/olescript',
        value: 'axs',
      },
      {
        type: 'application/pdf',
        value: 'pdf',
      },
      {
        type: 'application/pics-rules',
        value: 'prf',
      },
      {
        type: 'application/pkcs10',
        value: 'p10',
      },
      {
        type: 'application/pkix-crl',
        value: 'crl',
      },
      {
        type: 'application/postscript',
        value: 'ai',
      },
      {
        type: 'application/postscript',
        value: 'eps',
      },
      {
        type: 'application/postscript',
        value: 'ps',
      },
      {
        type: 'application/rtf',
        value: 'rtf',
      },
      {
        type: 'application/set-payment-initiation',
        value: 'setpay',
      },
      {
        type: 'application/set-registration-initiation',
        value: 'setreg',
      },
      {
        type: 'application/vnd.ms-excel',
        value: 'xla',
      },
      {
        type: 'application/vnd.ms-excel',
        value: 'xlc',
      },
      {
        type: 'application/vnd.ms-excel',
        value: 'xlm',
      },
      {
        type: 'application/vnd.ms-excel',
        value: 'xls',
      },
      {
        type: 'application/vnd.ms-excel',
        value: 'xlt',
      },
      {
        type: 'application/vnd.ms-excel',
        value: 'xlw',
      },
      {
        type: 'application/vnd.ms-outlook',
        value: 'msg',
      },
      {
        type: 'application/vnd.ms-pkicertstore',
        value: 'sst',
      },
      {
        type: 'application/vnd.ms-pkiseccat',
        value: 'cat',
      },
      {
        type: 'application/vnd.ms-pkistl',
        value: 'stl',
      },
      {
        type: 'application/vnd.ms-powerpoint',
        value: 'pot',
      },
      {
        type: 'application/vnd.ms-powerpoint',
        value: 'pps',
      },
      {
        type: 'application/vnd.ms-powerpoint',
        value: 'ppt',
      },
      {
        type: 'application/vnd.ms-project',
        value: 'mpp',
      },
      {
        type: 'application/vnd.ms-works',
        value: 'wcm',
      },
      {
        type: 'application/vnd.ms-works',
        value: 'wdb',
      },
      {
        type: 'application/vnd.ms-works',
        value: 'wks',
      },
      {
        type: 'application/vnd.ms-works',
        value: 'wps',
      },
      {
        type: 'application/winhlp',
        value: 'hlp',
      },
      {
        type: 'application/x-bcpio',
        value: 'bcpio',
      },
      {
        type: 'application/x-cdf',
        value: 'cdf',
      },
      {
        type: 'application/x-compress',
        value: 'z',
      },
      {
        type: 'application/x-compressed',
        value: 'tgz',
      },
      {
        type: 'application/x-cpio',
        value: 'cpio',
      },
      {
        type: 'application/x-csh',
        value: 'csh',
      },
      {
        type: 'application/x-director',
        value: 'dcr',
      },
      {
        type: 'application/x-director',
        value: 'dir',
      },
      {
        type: 'application/x-director',
        value: 'dxr',
      },
      {
        type: 'application/x-dvi',
        value: 'dvi',
      },
      {
        type: 'application/x-gtar',
        value: 'gtar',
      },
      {
        type: 'application/x-gzip',
        value: 'gz',
      },
      {
        type: 'application/x-hdf',
        value: 'hdf',
      },
      {
        type: 'application/x-internet-signup',
        value: 'ins',
      },
      {
        type: 'application/x-internet-signup',
        value: 'isp',
      },
      {
        type: 'application/x-iphone',
        value: 'iii',
      },
      {
        type: 'application/x-javascript',
        value: 'js',
      },
      {
        type: 'application/x-latex',
        value: 'latex',
      },
      {
        type: 'application/x-msaccess',
        value: 'mdb',
      },
      {
        type: 'application/x-mscardfile',
        value: 'crd',
      },
      {
        type: 'application/x-msclip',
        value: 'clp',
      },
      {
        type: 'application/x-msdownload',
        value: 'dll',
      },
      {
        type: 'application/x-msmediaview',
        value: 'm13',
      },
      {
        type: 'application/x-msmediaview',
        value: 'm14',
      },
      {
        type: 'application/x-msmediaview',
        value: 'mvb',
      },
      {
        type: 'application/x-msmetafile',
        value: 'wmf',
      },
      {
        type: 'application/x-msmoney',
        value: 'mny',
      },
      {
        type: 'application/x-mspublisher',
        value: 'pub',
      },
      {
        type: 'application/x-msschedule',
        value: 'scd',
      },
      {
        type: 'application/x-msterminal',
        value: 'trm',
      },
      {
        type: 'application/x-mswrite',
        value: 'wri',
      },
      {
        type: 'application/x-netcdf',
        value: 'cdf',
      },
      {
        type: 'application/x-netcdf',
        value: 'nc',
      },
      {
        type: 'application/x-perfmon',
        value: 'pma',
      },
      {
        type: 'application/x-perfmon',
        value: 'pmc',
      },
      {
        type: 'application/x-perfmon',
        value: 'pml',
      },
      {
        type: 'application/x-perfmon',
        value: 'pmr',
      },
      {
        type: 'application/x-perfmon',
        value: 'pmw',
      },
      {
        type: 'application/x-pkcs12',
        value: 'p12',
      },
      {
        type: 'application/x-pkcs12',
        value: 'pfx',
      },
      {
        type: 'application/x-pkcs7-certificates',
        value: 'p7b',
      },
      {
        type: 'application/x-pkcs7-certificates',
        value: 'spc',
      },
      {
        type: 'application/x-pkcs7-certreqresp',
        value: 'p7r',
      },
      {
        type: 'application/x-pkcs7-mime',
        value: 'p7c',
      },
      {
        type: 'application/x-pkcs7-mime',
        value: 'p7m',
      },
      {
        type: 'application/x-pkcs7-signature',
        value: 'p7s',
      },
      {
        type: 'application/x-sh',
        value: 'sh',
      },
      {
        type: 'application/x-shar',
        value: 'shar',
      },
      {
        type: 'application/x-shockwave-flash',
        value: 'swf',
      },
      {
        type: 'application/x-stuffit',
        value: 'sit',
      },
      {
        type: 'application/x-sv4cpio',
        value: 'sv4cpio',
      },
      {
        type: 'application/x-sv4crc',
        value: 'sv4crc',
      },
      {
        type: 'application/x-tar',
        value: 'tar',
      },
      {
        type: 'application/x-tcl',
        value: 'tcl',
      },
      {
        type: 'application/x-tex',
        value: 'tex',
      },
      {
        type: 'application/x-texinfo',
        value: 'texi',
      },
      {
        type: 'application/x-texinfo',
        value: 'texinfo',
      },
      {
        type: 'application/x-troff',
        value: 'roff',
      },
      {
        type: 'application/x-troff',
        value: 't',
      },
      {
        type: 'application/x-troff',
        value: 'tr',
      },
      {
        type: 'application/x-troff-man',
        value: 'man',
      },
      {
        type: 'application/x-troff-me',
        value: 'me',
      },
      {
        type: 'application/x-troff-ms',
        value: 'ms',
      },
      {
        type: 'application/x-ustar',
        value: 'ustar',
      },
      {
        type: 'application/x-wais-source',
        value: 'src',
      },
      {
        type: 'application/x-x509-ca-cert',
        value: 'cer',
      },
      {
        type: 'application/x-x509-ca-cert',
        value: 'crt',
      },
      {
        type: 'application/x-x509-ca-cert',
        value: 'der',
      },
      {
        type: 'application/ynd.ms-pkipko',
        value: 'pko',
      },
      {
        type: 'application/zip',
        value: 'zip',
      },
      {
        type: 'audio/basic',
        value: 'au',
      },
      {
        type: 'audio/basic',
        value: 'snd',
      },
      {
        type: 'audio/mid',
        value: 'mid',
      },
      {
        type: 'audio/mid',
        value: 'rmi',
      },
      {
        type: 'audio/mpeg',
        value: 'mp3',
      },
      {
        type: 'audio/x-aiff',
        value: 'aif',
      },
      {
        type: 'audio/x-aiff',
        value: 'aifc',
      },
      {
        type: 'audio/x-aiff',
        value: 'aiff',
      },
      {
        type: 'audio/x-mpegurl',
        value: 'm3u',
      },
      {
        type: 'audio/x-pn-realaudio',
        value: 'ra',
      },
      {
        type: 'audio/x-pn-realaudio',
        value: 'ram',
      },
      {
        type: 'audio/x-wav',
        value: 'wav',
      },
      {
        type: 'image/bmp',
        value: 'bmp',
      },
      {
        type: 'image/cis-cod',
        value: 'cod',
      },
      {
        type: 'image/gif',
        value: 'gif',
      },
      {
        type: 'image/ief',
        value: 'ief',
      },
      {
        type: 'image/jpeg',
        value: 'jpe',
      },
      {
        type: 'image/jpeg',
        value: 'jpeg',
      },
      {
        type: 'image/jpeg',
        value: 'jpg',
      },
      {
        type: 'image/pipeg',
        value: 'jfif',
      },
      {
        type: 'image/svg+xml',
        value: 'svg',
      },
      {
        type: 'image/tiff',
        value: 'tif',
      },
      {
        type: 'image/tiff',
        value: 'tiff',
      },
      {
        type: 'image/x-cmu-raster',
        value: 'ras',
      },
      {
        type: 'image/x-cmx',
        value: 'cmx',
      },
      {
        type: 'image/x-icon',
        value: 'ico',
      },
      {
        type: 'image/x-portable-anymap',
        value: 'pnm',
      },
      {
        type: 'image/x-portable-bitmap',
        value: 'pbm',
      },
      {
        type: 'image/x-portable-graymap',
        value: 'pgm',
      },
      {
        type: 'image/x-portable-pixmap',
        value: 'ppm',
      },
      {
        type: 'image/x-rgb',
        value: 'rgb',
      },
      {
        type: 'image/x-xbitmap',
        value: 'xbm',
      },
      {
        type: 'image/x-xpixmap',
        value: 'xpm',
      },
      {
        type: 'image/x-xwindowdump',
        value: 'xwd',
      },
      {
        type: 'message/rfc822',
        value: 'mht',
      },
      {
        type: 'message/rfc822',
        value: 'mhtml',
      },
      {
        type: 'message/rfc822',
        value: 'nws',
      },
      {
        type: 'text/css',
        value: 'css',
      },
      {
        type: 'text/h323',
        value: '323',
      },
      {
        type: 'text/html',
        value: 'htm',
      },
      {
        type: 'text/html',
        value: 'html',
      },
      {
        type: 'text/html',
        value: 'stm',
      },
      {
        type: 'text/iuls',
        value: 'uls',
      },
      {
        type: 'text/plain',
        value: 'bas',
      },
      {
        type: 'text/plain',
        value: 'c',
      },
      {
        type: 'text/plain',
        value: 'h',
      },
      {
        type: 'text/plain',
        value: 'txt',
      },
      {
        type: 'text/richtext',
        value: 'rtx',
      },
      {
        type: 'text/scriptlet',
        value: 'sct',
      },
      {
        type: 'text/tab-separated-values',
        value: 'tsv',
      },
      {
        type: 'text/webviewhtml',
        value: 'htt',
      },
      {
        type: 'text/x-component',
        value: 'htc',
      },
      {
        type: 'text/x-setext',
        value: 'etx',
      },
      {
        type: 'text/x-vcard',
        value: 'vcf',
      },
      {
        type: 'video/mpeg',
        value: 'mp2',
      },
      {
        type: 'video/mpeg',
        value: 'mpa',
      },
      {
        type: 'video/mpeg',
        value: 'mpe',
      },
      {
        type: 'video/mpeg',
        value: 'mpeg',
      },
      {
        type: 'video/mpeg',
        value: 'mpg',
      },
      {
        type: 'video/mpeg',
        value: 'mpv2',
      },
      {
        type: 'video/quicktime',
        value: 'mov',
      },
      {
        type: 'video/quicktime',
        value: 'qt',
      },
      {
        type: 'video/x-la-asf',
        value: 'lsf',
      },
      {
        type: 'video/x-la-asf',
        value: 'lsx',
      },
      {
        type: 'video/x-ms-asf',
        value: 'asf',
      },
      {
        type: 'video/x-ms-asf',
        value: 'asr',
      },
      {
        type: 'video/x-ms-asf',
        value: 'asx',
      },
      {
        type: 'video/x-msvideo',
        value: 'avi',
      },
      {
        type: 'video/x-sgi-movie',
        value: 'movie',
      },
      {
        type: 'x-world/x-vrml',
        value: 'flr',
      },
      {
        type: 'x-world/x-vrml',
        value: 'vrml',
      },
      {
        type: 'x-world/x-vrml',
        value: 'wrl',
      },
      {
        type: 'x-world/x-vrml',
        value: 'wrz',
      },
      {
        type: 'x-world/x-vrml',
        value: 'xaf',
      },
      {
        type: 'x-world/x-vrml',
        value: 'xof',
      },
    ];
    let e = name.split('.')[1];
    for (let a in data) {
      if (data[a].value == e) {
        return data[a].type;
      }
    }
    return '';
  },
  // 差值时间计算
  getValue(time1, time2) {
    var time1 = new Date(time1); //转换为中国标准时间
    var time2 = new Date(time2);
    var time1 = time1.getTime(); //转换为时间戳
    var time2 = time2.getTime();
    var runTime = (time2 - time1) / 1000; //开始得出时间差,然后计算
    var year = Math.floor(runTime / 86400 / 365);
    runTime = runTime % (86400 * 365);
    var month = Math.floor(runTime / 86400 / 30);
    runTime = runTime % (86400 * 30);
    var day = Math.floor(runTime / 86400);
    runTime = runTime % 86400;
    var hour = Math.floor(runTime / 3600);
    runTime = runTime % 3600;
    var minute = Math.floor(runTime / 60);
    runTime = runTime % 60;
    var second = runTime;

    return year != 0
      ? year + '年'
      : '' + month != 0
        ? month + '月'
        : '' + day != 0
          ? day + '天'
          : '' + hour != 0
            ? hour + '小时'
            : '' + minute != 0
              ? minute + '分'
              : '' + second != 0
                ? second + '秒'
                : '';
  },
};
export function arrayToTree(data, parent, pname = 'parentId', overLabel = 'isLast') {
  const tree = data.filter(item => item[pname] === parent).map(item => {
    const datas = arrayToTree(data, item.tag)
    if (datas.length > 0) {
      item.chargeParamList = datas
      item[overLabel] = false
    } else {
      item[overLabel] = true
    }
    return item
  })
  return tree
}
